package com.yanqu.road.dao.impl.activity.game2048;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.game.ActivityPageantInfo;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class PageantConfigDaoImpl extends TempDao {

    /**
     * 获取活动配置表
     *
     * @return
     */
    public List<ActivityPageantInfo> getActivityPageantConfig(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        List<ActivityPageantInfo> result = new ArrayList<>();
        String sql = "select * from t_s_activity_pageant WHERE activityId = ?";

        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                ActivityPageantInfo data = new ActivityPageantInfo();
                data.setActivityId(rs.getInt("activityId"));
                data.setId(rs.getInt("id"));
                data.setLevel(rs.getInt("level"));
                data.setName(rs.getString("name"));
                data.setDesc(rs.getString("desc"));
                data.setIcon(rs.getInt("icon"));
                data.setSorceMerge(rs.getInt("sorceMerge"));
                data.setMoneyMerge(rs.getInt("moneyMerge"));
                data.setEffectFirstMerge(rs.getString("effectFirstMerge"));
                data.setRandomBox(rs.getString("randomBox"));
                result.add(data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }
}
